package com.killgun.physics;

import com.jme3.app.Application;
import com.jme3.app.state.AppStateManager;
import com.jme3.bullet.BulletAppState;
import com.jme3.bullet.collision.shapes.SphereCollisionShape;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.bullet.objects.PhysicsCharacter;
import com.jme3.scene.Spatial;
import com.killgun.MainApp;
import com.killgun.configuration.ConfigManager;
import java.util.Properties;

/**
 *
 * @author Austin Allman
 */
public class PhysicsAppState extends BulletAppState {

    private MainApp main;
    private static final Properties prop = ConfigManager.getInstance();
    public static final int JUMP_SPEED = Integer.parseInt(prop.getProperty(
            "phys.jump_speed"));
    public static final int FALL_SPEED = Integer.parseInt(prop.getProperty(
            "phys.fall_speed"));
    public static final int GRAVITY = Integer.parseInt(prop.getProperty(
            "phys.gravity"));

    @Override
    public void initialize(AppStateManager stateManager, Application app) {
        super.initialize(stateManager, app);
        main = (MainApp) app;
    }

    public RigidBodyControl addSolid(Spatial spatial) {
        RigidBodyControl rigidBodyControl = new RigidBodyControl(0);
        spatial.addControl(rigidBodyControl);
        getPhysicsSpace().add(rigidBodyControl);
        return rigidBodyControl;
    }

    public PhysicsCharacter addPlayer() {
        PhysicsCharacter player = new PhysicsCharacter(
                new SphereCollisionShape(5), .01f);
        player.setJumpSpeed(JUMP_SPEED);
        player.setFallSpeed(FALL_SPEED);
        player.setGravity(GRAVITY);
        getPhysicsSpace().add(player);
        return player;
    }
}
